package com.jhhc.StormSurgeForecast.AstronomicalTide.ServiceImpl;

import com.jhhc.RHDB.Data.Pojo.ST_RIVER_R;
import com.jhhc.RHDB.Data.Service.ST_RIVER_RService;
import com.jhhc.StormSurgeForecast.AstronomicalTide.Pojo.DTO.UploadWindSiteDto;
import com.jhhc.StormSurgeForecast.AstronomicalTide.Pojo.DTO.WindSiteParam;
import com.jhhc.StormSurgeForecast.AstronomicalTide.Service.WindService;
import com.jhhc.StormSurgeForecast.AstronomicalTide.Util.TimeUtil;
import com.jhhc.StormSurgeForecast.AstronomicalTide.Util.WindSiteUtil;
import com.jhhc.StormSurgeForecast.Calculate.util.CalUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;

/**
 * @author LYQ
 */
@Service
@RequiredArgsConstructor
public class WindServiceImpl implements WindService {

    private final TimeUtil timeUtil = new TimeUtil();

    private final ST_RIVER_RService riverRService;


    @Override
    public String createWindSite(WindSiteParam param) {
        //根据作业预报时间选择风场文件
        //输出文件地址
        //预热期
        if (param.getType() == 1) {
            String yrsTime = timeUtil.dateAddDay(param.getForecastTime(),-2);
            String yreTime = timeUtil.dateAddHour(param.getForecastTime(),-1);
            String yrPath = param.getLocalFile() + File.separator + WindSiteUtil.getWindPath1(yrsTime);
            //读取文件获取数据
            WindSiteUtil.createFile(param.getWindSiteFile(),WindSiteUtil.getHeadInfo(yrsTime,param.getEndTime()));
            WindSiteUtil.readNc(yrPath,param.getRegion(),yrsTime,yreTime,param.getWindSiteFile());
            //预报期
            String ybPath = param.getLocalFile() + File.separator + WindSiteUtil.getWindPath(param.getForecastTime());
            WindSiteUtil.readNc(ybPath,param.getRegion(),param.getForecastTime(),param.getEndTime(),param.getWindSiteFile());

            //生成流量文件
            List<ST_RIVER_R> stRiverRs = riverRService.queryModel(timeUtil.dateAddDay(param.getForecastTime(),-1),param.getEndTime());
            CalUtil calUtil = new CalUtil();
            calUtil.createDisbase(stRiverRs,param.getQPath());
        }else if (param.getType() == 2) {
            //生成流量文件
            List<ST_RIVER_R> stRiverRs = riverRService.queryModel(timeUtil.dateAddDay(param.getForecastTime(),-1),param.getEndTime());
            CalUtil calUtil = new CalUtil();
            calUtil.createDisbase(stRiverRs,param.getQPath());
        }
        return param.getWindSiteFile();
    }


    @Override
    public String createWindSiteXY(String path,String scPath,String region) {
        return WindSiteUtil.readNcXY(path, scPath, region);
    }

    @Override
    public void uploadWindSite(UploadWindSiteDto param) {


    }
}
